﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Nextropia.C2Manager.C2API
{
    /// <summary>
    /// represents a price quote for a given symbol, at a given point in time
    /// </summary>
    public class Price
    {
        /// <summary>
        /// the most current best bid
        /// </summary>
        public decimal Bid { get; set; }

        /// <summary>
        /// the most current best ask
        /// </summary>
        public decimal Ask { get; set; }

        /// <summary>
        /// the most current trade price
        /// </summary>
        public decimal Last { get; set; }

        /// <summary>
        /// the time at which this quote was obtained
        /// </summary>
        public DateTime Timestamp { get; set; }

        /// <summary>
        /// the symbol for which this quote was obtained
        /// </summary>
        public string Symbol { get; set; }

        /// <summary>
        /// default constructor
        /// </summary>
        public Price()
        {
        }

        internal Price(XmlNode sourceNode)
        {
            Bid = C2Service.SafeParseDecimal(sourceNode.SelectSingleNode("bid").InnerText);
            Ask = C2Service.SafeParseDecimal(sourceNode.SelectSingleNode("ask").InnerText);
            Last = C2Service.SafeParseDecimal(sourceNode.SelectSingleNode("last").InnerText);
            Timestamp = C2Service.SafeParseDate(sourceNode.SelectSingleNode("tick").InnerText);
        }
    }
}
